package cn.zn.modules.budget.cur.service.impl;

import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.Query;
import cn.zn.modules.budget.cur.dao.TBudgetIncomeMapper;
import cn.zn.modules.budget.cur.entity.TBudgetIncome;
import cn.zn.modules.budget.cur.entity.TBudgetIncomeTag;
import cn.zn.modules.budget.cur.service.TBudgetIncomeService;
import cn.zn.modules.budget.cur.service.TBudgetIncomeTagService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class TBudgetIncomeServiceImpl extends ServiceImpl<TBudgetIncomeMapper, TBudgetIncome> implements TBudgetIncomeService {

    @Autowired
    private TBudgetIncomeTagService tBudgetIncomeTagService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TBudgetIncome> page = this.page(
                new Query<TBudgetIncome>().getPage(params),
                new QueryWrapper<TBudgetIncome>().orderByDesc("TRANS_DATE_")
        );

        return new PageUtils(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteIncome(List<String> ids) {
        tBudgetIncomeTagService.remove(new QueryWrapper<TBudgetIncomeTag>().in("T_BUDGET_INCOME_ID_", ids));
        super.removeByIds(ids);
    }
}
